package com.oa.official.controller;

import com.oa.official.service.SysRoleService;
import com.oa.official.service.SysUserService;
import com.oa.official.entity.system.SysUser;
import com.oa.official.response.Result;

import com.oa.official.vo.system.SysUserQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "用户管理")
@RestController
@RequestMapping(path = {"/admin/system/sysUser"})
public class SysUserController {
    @Resource
    private SysUserService sysUserService;
    @Resource
    private SysRoleService sysRoleService;


    @ApiOperation("用户分页列表")
    @GetMapping(path = "/{page}/{limit}")
    public Result list(@PathVariable(value = "page")Integer page,
                       @PathVariable(value = "limit")Integer limit,
                       SysUserQueryVo sysUserQueryVo){
        return sysUserService.list(page,limit,sysUserQueryVo);
    }

    @ApiOperation("根据id查询用户信息")
    @GetMapping(path = "/get/{id}")
    public Result findByUserId(@PathVariable(value = "id")Long id){
        return sysUserService.findByUserId(id);
    }

    @ApiOperation("删除用户")
    @DeleteMapping(path = "/remove/{id}")
    public Result deleteById(@PathVariable(value = "id")Long id){
        return sysUserService.deleteById(id);
    }

    @ApiOperation("新增用户")
    @PostMapping(path = "/save")
    public Result save(@RequestBody SysUser sysUser){
        return sysUserService.save(sysUser);
    }

    @ApiOperation("修改用户")
    @PutMapping (path = "/update")
    public Result updateUser(@RequestBody SysUser sysUser){
        return sysUserService.update(sysUser);
    }

    @ApiOperation(value = "更新状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,
                               @PathVariable Integer status) {
        return sysUserService.updateStatus(id, status);
    }


}